package com.robotserver.orders.service.impl;

import com.robotserver.orders.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @Auther: jianghan
 * @Date: 2020/4/26 15:29
 * @Description:
 */
@Service
public class EmailServiceImpl implements EmailService {
    @Autowired
    private JavaMailSender mailSender;
    @Value("${tomail.users}")
    private String toUsers;
    @Value("${spring.mail.username}")
    private String fromUser;

    @Override
    public void sendMail(String title, String content) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(fromUser);
        message.setTo(toUsers);
        message.setSubject(title);
        message.setText(content);

        mailSender.send(message);
    }
}
